import {
  reqIndexData
} from "../../api/index"

import {
  store
} from "../../store/store"
import {
  createStoreBindings
} from "mobx-miniprogram-bindings"
Page({

  data: {
    loading: true,
    bannerList: [],
    categoryList: [], // 商品导航
    activeList: [], // 活动宣传区
    hostList: [], // 人气区域
    guessList: [], //猜你喜欢

  },
  onShareAppMessage: function () {
    return {
      title: '转发标题',
      path: '/pages/index/index',
      imageUrl: '自定义图片路径'
    }
  },
  onShareTimeline: function () {
    return {
      title: '转发标题',
      query: 'from=pyq',
      imageUrl: '自定义图片路径'
    }
  },
  onLoad: async function (options) {
    withShareTicket:true
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline']
    })
    const res = await reqIndexData()
    this.setData({
      bannerList: res[0].data,
      categoryList: res[1].data,
      activeList: res[2].data,
      hostList: res[3].data,
      guessList: res[4].data
    })
    this.storeBindings = createStoreBindings(this, {
      store,
      fields: ["numA"]
    })
    wx.login({
      success: (res) => {
        console.log(res.code);
        wx.request({
          url: 'https://api.weixin.qq.com/sns/jscode2session',
          data: {
            js_code: res.code,
            secret: "7edb44df342965d788a0da904da6f6de",
            appid: "wx394ec204c484be52",
            grant_type: "authorization_code"
          },
          success: ({data}) => {
            console.log(data.openid);
            console.log(data.session_key);
          }
        })
      },
    })
  },
  onReady: function () {
    this.setData({
      loading: false
    })
  },
  onShow: function () {

  },

  onHide: function () {

  },
  onUnload: function () {
    this.storeBindings.destroyStoreBindings()
  },
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
 
  
})